<template>
    <div>
        <el-dialog title="修改学生" :visible.sync="visible" @open="handleOpen">
            <el-form :model="student">
                <el-form-item label="姓名" :label-width="formLabelWidth">
                    <el-input v-model="student.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="年龄" :label-width="formLabelWidth">
                    <el-input v-model="student.age" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="性别" :label-width="formLabelWidth">
                    <el-radio v-model="student.gender" label="男">男</el-radio>
                    <el-radio v-model="student.gender" label="女">女</el-radio>
                </el-form-item>
                <el-form-item label="选择班级" :label-width="formLabelWidth">
                    <el-select v-model="student.classes" placeholder="请选择">
                        <el-option v-for="item in classAry" :key="item._id" :label="item.name" :value="item._id">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="visible = false">取 消</el-button>
                <el-button type="primary" @click="handleUpdate">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { update } from '../../services/student';
import { findAll } from '@/services/class';
import { mapMutations, mapState } from 'vuex';
export default {
    components: {
        
    },
    props: [],
    data() {
        return {
            classAry: [],
            formLabelWidth: '90px'
        }
    },
    computed:{
        visible:{
            get(){
                return this.updateVisible;
            },
            set(visible){
                this.setUpdateVisible(visible);
            }
        },
        ...mapState('student',['updateVisible','student'])
    },
    methods: {
        async handleUpdate() {
            await update(this.student);
            this.$emit('show');
            this.visible = false;
        },
        async handleOpen(){
            this.classAry = await findAll();
        },
        ...mapMutations('student',['setUpdateVisible'])
    }
}
</script>
<style>

</style>